package cn.funnyxb.tools.appFrame.util.net;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Message;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import cn.funnyxb.tools.appFrame.util.FileTool;
import cn.funnyxb.tools.appFrame.util.net.exceptions.Exception_ActiveConnectionIsNotAvailable;
import cn.funnyxb.tools.appFrame.util.net.exceptions.Exception_CannotGetConnectionSource;
import cn.funnyxb.tools.appFrame.util.net.exceptions.Exception_ResponseCodeIsNot200;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

public class NetHelper
{
  private static Uri URI_APN_PREFER = Uri.parse("content://telephony/carriers/preferapn");
  private Context context;

  public NetHelper(Context paramContext)
  {
    this.context = paramContext;
  }

  public static void log(String paramString)
  {
    Debuger.log("nethelper", paramString);
  }

  public void asyncGetUrlInputStream(String paramString, OnGetInputStreamListener paramOnGetInputStreamListener)
  {
    new AsyncTask(paramString, paramOnGetInputStreamListener)
    {
      Exception exception = null;
      Integer resultCode = Integer.valueOf(1);

      // ERROR //
      protected Integer doInBackground(Void[] paramArrayOfVoid)
      {
        // Byte code:
        //   0: aconst_null
        //   1: astore_2
        //   2: aload_0
        //   3: getfield 24	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:this$0	Lcn/funnyxb/tools/appFrame/util/net/NetHelper;
        //   6: aload_0
        //   7: getfield 26	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:val$urlStr	Ljava/lang/String;
        //   10: invokevirtual 55	cn/funnyxb/tools/appFrame/util/net/NetHelper:getInputStream	(Ljava/lang/String;)Ljava/io/InputStream;
        //   13: astore_2
        //   14: aload_0
        //   15: getfield 28	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:val$onGetInputStreamListener	Lcn/funnyxb/tools/appFrame/util/net/NetHelper$OnGetInputStreamListener;
        //   18: aload_2
        //   19: invokeinterface 61 2 0
        //   24: aload_2
        //   25: ifnull +7 -> 32
        //   28: aload_2
        //   29: invokevirtual 66	java/io/InputStream:close	()V
        //   32: aload_0
        //   33: getfield 39	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:resultCode	Ljava/lang/Integer;
        //   36: areturn
        //   37: astore 7
        //   39: aload 7
        //   41: invokevirtual 69	java/net/MalformedURLException:printStackTrace	()V
        //   44: aload_0
        //   45: iconst_2
        //   46: invokestatic 37	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
        //   49: putfield 39	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:resultCode	Ljava/lang/Integer;
        //   52: aload_0
        //   53: aload 7
        //   55: putfield 41	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:exception	Ljava/lang/Exception;
        //   58: goto -34 -> 24
        //   61: astore 6
        //   63: aload 6
        //   65: invokevirtual 70	java/io/IOException:printStackTrace	()V
        //   68: aload_0
        //   69: iconst_3
        //   70: invokestatic 37	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
        //   73: putfield 39	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:resultCode	Ljava/lang/Integer;
        //   76: aload_0
        //   77: aload 6
        //   79: putfield 41	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:exception	Ljava/lang/Exception;
        //   82: goto -58 -> 24
        //   85: astore 5
        //   87: aload_0
        //   88: iconst_5
        //   89: invokestatic 37	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
        //   92: putfield 39	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:resultCode	Ljava/lang/Integer;
        //   95: aload_0
        //   96: aload 5
        //   98: putfield 41	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:exception	Ljava/lang/Exception;
        //   101: goto -77 -> 24
        //   104: astore_3
        //   105: aload_0
        //   106: iconst_4
        //   107: invokestatic 37	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
        //   110: putfield 39	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:resultCode	Ljava/lang/Integer;
        //   113: aload_0
        //   114: aload_3
        //   115: putfield 41	cn/funnyxb/tools/appFrame/util/net/NetHelper$1:exception	Ljava/lang/Exception;
        //   118: goto -94 -> 24
        //   121: astore 4
        //   123: goto -91 -> 32
        //
        // Exception table:
        //   from	to	target	type
        //   2	24	37	java/net/MalformedURLException
        //   2	24	61	java/io/IOException
        //   2	24	85	cn/funnyxb/tools/appFrame/util/net/exceptions/Exception_CannotGetConnectionSource
        //   2	24	104	java/lang/Exception
        //   28	32	121	java/lang/Exception
      }

      protected void onPostExecute(Integer paramInteger)
      {
        switch (this.resultCode.intValue())
        {
        default:
        case 1:
        case 3:
        case 2:
        case 5:
        case 4:
        }
        while (true)
        {
          return;
          this.val$onGetInputStreamListener.onWorkCompleteOnparentThread();
          continue;
          this.val$onGetInputStreamListener.onIOException((IOException)this.exception);
          continue;
          this.val$onGetInputStreamListener.onMalformedURLException((MalformedURLException)this.exception);
          continue;
          this.val$onGetInputStreamListener.cannotGetConnectionSource();
          continue;
          this.val$onGetInputStreamListener.onExceptionWhenProccessInputStream(this.exception);
        }
      }
    }
    .execute(new Void[0]);
  }

  public boolean downloadFile(String paramString1, String paramString2)
    throws MalformedURLException, IOException, Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable, Exception_ResponseCodeIsNot200
  {
    return FileTool.turnInputStream2File(getInputStream(paramString1), paramString2);
  }

  public String downloadTxtFile2String(String paramString, Charset paramCharset)
    throws MalformedURLException, IOException, Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable, Exception_ResponseCodeIsNot200
  {
    BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(getInputStream(paramString), paramCharset));
    StringBuilder localStringBuilder = new StringBuilder();
    while (true)
    {
      String str = localBufferedReader.readLine();
      if (str == null);
      try
      {
        localBufferedReader.close();
        label45: return localStringBuilder.toString();
        localStringBuilder.append(str);
      }
      catch (Exception localException)
      {
        break label45:
      }
    }
  }

  public int getConnectionType()
    throws Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable
  {
    log("getConnectionType start");
    ConnectivityManager localConnectivityManager = (ConnectivityManager)this.context.getSystemService("connectivity");
    NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
    (3000 - 500);
    if (localNetworkInfo == null)
    {
      log("sorry getConnectionType networkinfo=null");
      throw new Exception_CannotGetConnectionSource();
    }
    if (!(localNetworkInfo.isAvailable()))
    {
      log("getConnectionType networkinfo!=null,but isNotAvailable");
      throw new Exception_ActiveConnectionIsNotAvailable();
    }
    log("getConnectionType availlable");
    return localConnectivityManager.getActiveNetworkInfo().getType();
  }

  // ERROR //
  public Proxy getHttpProxy()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 34	cn/funnyxb/tools/appFrame/util/net/NetHelper:context	Landroid/content/Context;
    //   4: invokevirtual 150	android/content/Context:getContentResolver	()Landroid/content/ContentResolver;
    //   7: getstatic 28	cn/funnyxb/tools/appFrame/util/net/NetHelper:URI_APN_PREFER	Landroid/net/Uri;
    //   10: aconst_null
    //   11: aconst_null
    //   12: aconst_null
    //   13: aconst_null
    //   14: invokevirtual 156	android/content/ContentResolver:query	(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
    //   17: astore_1
    //   18: getstatic 162	java/lang/System:out	Ljava/io/PrintStream;
    //   21: new 92	java/lang/StringBuilder
    //   24: dup
    //   25: ldc 164
    //   27: invokespecial 166	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   30: aload_1
    //   31: invokevirtual 169	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   34: invokevirtual 103	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   37: invokevirtual 174	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   40: aload_1
    //   41: ifnull +12 -> 53
    //   44: aload_1
    //   45: invokeinterface 179 1 0
    //   50: ifne +7 -> 57
    //   53: aconst_null
    //   54: astore_2
    //   55: aload_2
    //   56: areturn
    //   57: aload_1
    //   58: aload_1
    //   59: ldc 181
    //   61: invokeinterface 185 2 0
    //   66: invokeinterface 189 2 0
    //   71: astore_3
    //   72: aload_1
    //   73: aload_1
    //   74: ldc 191
    //   76: invokeinterface 185 2 0
    //   81: invokeinterface 189 2 0
    //   86: invokestatic 196	java/lang/Integer:parseInt	(Ljava/lang/String;)I
    //   89: istore 6
    //   91: aload_1
    //   92: invokeinterface 197 1 0
    //   97: getstatic 162	java/lang/System:out	Ljava/io/PrintStream;
    //   100: new 92	java/lang/StringBuilder
    //   103: dup
    //   104: ldc 199
    //   106: invokespecial 166	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   109: aload_3
    //   110: invokevirtual 107	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   113: ldc 201
    //   115: invokevirtual 107	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   118: iload 6
    //   120: invokevirtual 204	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   123: invokevirtual 103	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   126: invokevirtual 174	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   129: aload_3
    //   130: ifnull +65 -> 195
    //   133: aload_3
    //   134: ldc 206
    //   136: invokevirtual 212	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   139: ifne +56 -> 195
    //   142: iload 6
    //   144: ifle +51 -> 195
    //   147: new 214	java/net/Proxy
    //   150: dup
    //   151: getstatic 220	java/net/Proxy$Type:HTTP	Ljava/net/Proxy$Type;
    //   154: new 222	java/net/InetSocketAddress
    //   157: dup
    //   158: aload_3
    //   159: iload 6
    //   161: invokespecial 225	java/net/InetSocketAddress:<init>	(Ljava/lang/String;I)V
    //   164: invokespecial 228	java/net/Proxy:<init>	(Ljava/net/Proxy$Type;Ljava/net/SocketAddress;)V
    //   167: astore_2
    //   168: goto -113 -> 55
    //   171: astore 5
    //   173: aload_1
    //   174: invokeinterface 197 1 0
    //   179: aconst_null
    //   180: astore_2
    //   181: goto -126 -> 55
    //   184: astore 4
    //   186: aload_1
    //   187: invokeinterface 197 1 0
    //   192: aload 4
    //   194: athrow
    //   195: aconst_null
    //   196: astore_2
    //   197: goto -142 -> 55
    //
    // Exception table:
    //   from	to	target	type
    //   72	91	171	java/lang/Exception
    //   72	91	184	finally
  }

  public InputStream getInputStream(String paramString)
    throws MalformedURLException, IOException, Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable, Exception_ResponseCodeIsNot200
  {
    return getInputStream(paramString, 5000, 5000);
  }

  public InputStream getInputStream(String paramString, int paramInt1, int paramInt2)
    throws MalformedURLException, IOException, Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable, Exception_ResponseCodeIsNot200
  {
    log("getInputStrem 1 start=" + System.currentTimeMillis());
    HttpURLConnection localHttpURLConnection = (HttpURLConnection)getUrlConnection(paramString);
    log("getInputStrem 2 getConncetion responsecode=" + localHttpURLConnection.getResponseCode() + "   at:" + System.currentTimeMillis() + " conn=" + localHttpURLConnection);
    localHttpURLConnection.setConnectTimeout(paramInt1);
    localHttpURLConnection.setReadTimeout(paramInt2);
    log("response code=" + localHttpURLConnection.getResponseCode());
    if (localHttpURLConnection.getResponseCode() != 200)
      throw new Exception_ResponseCodeIsNot200();
    InputStream localInputStream = localHttpURLConnection.getInputStream();
    log("getInputStrem 3 getInputStream=" + System.currentTimeMillis() + " result=" + localInputStream);
    return localInputStream;
  }

  public URLConnection getUrlConnection(String paramString)
    throws MalformedURLException, IOException, Exception_CannotGetConnectionSource, Exception_ActiveConnectionIsNotAvailable
  {
    log("getUrlConnection url=" + paramString);
    log("getUrlConnection startTime=" + System.currentTimeMillis());
    if (getConnectionType() == 1)
      log("getUrlConnection  10");
    URLConnection localURLConnection1;
    for (Object localObject = new URL(paramString).openConnection(); ; localObject = localURLConnection1)
    {
      while (true)
      {
        return localObject;
        log("getUrlConnection  20");
        Proxy localProxy = getHttpProxy();
        if (localProxy == null)
          break;
        log("getUrlConnection 2 noProxy openConncetionTime=" + System.currentTimeMillis());
        URLConnection localURLConnection2 = new URL(paramString).openConnection(localProxy);
        log("getUrlConnection 3 noProxy  opentime=" + System.currentTimeMillis());
        log("getUrlConnection 4 noProxy result=" + localURLConnection2);
        localObject = localURLConnection2;
      }
      log("getUrlConnection 2 openConncetionTime=" + System.currentTimeMillis());
      localURLConnection1 = new URL(paramString).openConnection();
      log("getUrlConnection 3 opend=" + System.currentTimeMillis());
      log("getUrlConnection 4 result=" + localURLConnection1);
    }
  }

  public static abstract interface OnDownCompleteListener
  {
    public static final int CannotWriteDest = 3;
    public static final int DestIsnotAFile = 2;
    public static final int Exception = 4;
    public static final int WELLDONE = 1;

    public abstract void onComplete(Message paramMessage);
  }

  public static abstract interface OnGetInputStreamListener
  {
    public static final int ExceptionWhenProccess = 4;
    public static final int Exception_noConnectSource = 5;
    public static final int IOException = 3;
    public static final int MalformedURLException = 2;
    public static final int WELLDONE = 1;

    public abstract void cannotGetConnectionSource();

    public abstract Message getResultMsg();

    public abstract void onConnectInputStream(InputStream paramInputStream)
      throws Exception;

    public abstract void onExceptionWhenProccessInputStream(Exception paramException);

    public abstract void onIOException(IOException paramIOException);

    public abstract void onMalformedURLException(MalformedURLException paramMalformedURLException);

    public abstract void onWorkCompleteOnparentThread();

    public abstract void setResultMsg(Message paramMessage);
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.tools.appFrame.util.net.NetHelper
 * JD-Core Version:    0.5.3
 */